package com.wwinsoft.oa.service.terminal;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.wwinsoft.modules.orm.Page;
import com.wwinsoft.modules.utils.PropertiesUtils;
import com.wwinsoft.oa.dao.terminal.TerminalMaintainDao;
import com.wwinsoft.oa.dao.terminal.TerminalMaintainQueryDao;
import com.wwinsoft.oa.entity.terminal.TerminalMaintain;
import com.wwinsoft.oa.pojo.terminal.TerminalMaintainBean;

/**
 * @author: Tim Chen
 * @since 1.0
 */
@Service
@Transactional
public class TerminalService {

    @Autowired
    private TerminalMaintainDao terminalMaintainDao ;

    @Autowired
    private TerminalMaintainQueryDao terminalMaintainQueryDao ;

    public void saveTerminalMaintain(TerminalMaintain terminal){
          terminalMaintainDao.save(terminal);
    }

    @Transactional(readOnly = true)
    public  TerminalMaintain  getTerminalMaintain(Long id){
          return  terminalMaintainDao.get(id);
    }

    @Transactional(readOnly = true)
    public Page<TerminalMaintainBean> searchTerminalMaintain(Page<TerminalMaintainBean> page , Object filter) {
        Map paraMap = PropertiesUtils.toParameterMap(filter);
        return terminalMaintainQueryDao.searchTermialMaintainPage(page, paraMap);
    }

    @Transactional(readOnly = true)
    public List<TerminalMaintainBean> searchTerminalMaintain(Object filter) {
        Map paraMap = PropertiesUtils.toParameterMap(filter);
        return terminalMaintainQueryDao.searchTermialMaintain(paraMap);
    }

    public void archiveTerminalMaintain(Long id){
        TerminalMaintain terminalMaintain = terminalMaintainDao.get(id);
        terminalMaintain.setProcessEndTime(new Date());
        terminalMaintain.setStatus(TerminalMaintain.STATUS_COMPLETE);
        terminalMaintainDao.save(terminalMaintain);
    }
}
